package org.jackysoft.util;

import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
public class RowCopyWatcher extends AbstractRowWatcher {
   
    private Sheet oldSheet;
    private int lastRow;
	public RowCopyWatcher(Sheet sheet, int i) {
           this.oldSheet = sheet;
           this.lastRow = i;
	}

	@Override
	public void accept(Row oldrow) {
		Row tmprow = oldSheet.createRow(++lastRow);
    	Iterator<Cell> tmpCells = oldrow.cellIterator();
    	int cdx=0;
    	while(tmpCells.hasNext()){
    		Cell tc = tmpCells.next();
    	    int ctype = tc.getCellType();
    	    Cell ntc = tmprow.createCell(cdx++,ctype);
    	    switch(ctype){
    	    case Cell.CELL_TYPE_STRING:
    	    	ntc.setCellValue(tc.getStringCellValue());
    	    	break;
    	    case Cell.CELL_TYPE_NUMERIC:
    	    	ntc.setCellValue(ExcelUtil.cellNumber(tc));
    	    	break;
    	    default:
    	    	break;
    	    }
    	}
	}
	
	

}
